//
//  MFWHttpRequest.m
//  MFWSdk
//
//  Created by Song Xiaofeng on 13-7-24.
//  Copyright (c) 2013年 Mafengwo Inc. All rights reserved.
//

#import "MFWHttpRequest.h"
#import "NSString+EnDeCoding.h"
extern NSString *API_HOST;

@implementation MFWHttpRequest

+(MFWHttpRequest*) dataRequest
{
    return [[MFWHttpRequest alloc] init];
}

- (id)init {
    self = [super init];
    if (self) {
        _requestParams = [[NSMutableDictionary alloc] init];
        _dataParams = [[NSMutableDictionary alloc] init];
        _imageParams = [[NSMutableDictionary alloc] init];
        _headerParams = [[NSMutableDictionary alloc] init];
        
        _timeOutSeconds = 30;
        
        //默认为普通队列
        self.queueType = kMFWRequestQueueTypeNormal;
    }
    return self;
}

- (NSString*) requestUrl
{
    if (!_requestUrl)
    {
        _requestUrl = [NSString stringWithFormat:@"%@%@", API_HOST,
                _requestApi];
    }
    
    return _requestUrl;
    
}

- (void)cancel;
{
    [[MFWHttpEngine sharedInstance] cancelHttpRequest:self];
}

- (NSString*)description
{
    return [NSString stringWithFormat:@" MFWHttpRequest>>\n %@ \n args:%@ \n headers:%@", self.requestUrl, self.requestParams, self.headerParams];
}

- (BOOL)isEqual:(id)object
{
    if ([object isKindOfClass:[self class]])
    {
        MFWHttpRequest *aRequest = (MFWHttpRequest*)object;
        
        if ([aRequest.requestUrl isEqualToString:self.requestUrl]
            && (aRequest.task == self.task || ([aRequest.task isEqual:self.task])))
        {
            return YES;
        }
    
    }
    return NO;
}

- (NSString*)httpMethodStr
{
    switch (_httpMethod)
    {
        case kRequestHttpMethodGet:
            return @"GET";
            break;
        case kRequestHttpMethodPost:
            return @"POST";
            break;
        case kRequestHttpMethodPut:
            return @"PUT";
            break;
        case kRequestHttpMethodDelete:
            return @"DELETE";
            break;
        default:
            return @"";
            break;
    }
}
@end
